<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <body>
    <div id="output">
      <h2>The XMLHttpRequest 对象</h2>
      <button type="button" onclick="fetchDoc()">获取内容</button>
    </div>
    <script>
      function fetchDoc() {
        var httpRequest = new XMLHttpRequest();
        httpRequest.onreadystatechange = function () {
          if (this.readyState === 4 && this.status === 200) {
            document.getElementById("output").innerHTML = this.responseText;
          }
        };
        httpRequest.open("GET", "ajax_intro.txt", true);
        httpRequest.send();
      }
    </script>
  </body>
</html>
